//LSL-script

//#########################################################################
//        MYrss - Children
//
// (C) Copyright by Hachreak
//       Released under GPL v2.
//       Author : Hachreak (hachreak at gmail dot com)
//       WebSite: www.secondlifelab.it
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
//#########################################################################

key last_key;

default{

    state_entry(){
    }

    touch_start(integer total_number){
    //	last_key = llDetectedKey(0);
        state elab;
    }

    link_message(integer sender_num, integer num, string msg, key id) {
    	if(num == 0){
		// Comando di reset per lo script
		llResetScript();
	}
    }
}

state elab{

    state_entry(){
        // Richiedo la news
    	llMessageLinked(LINK_ROOT, llGetLinkNumber(), "", NULL_KEY);
	// timer x timeout (30 secondi)
	llSetTimerEvent(30);
    }

    // sender_num is the link number of the sending object in the set.
    // num, str, and id are arbitrary values passed to the llMessageLinked function.
    link_message(integer sender_num, integer num, string msg, key id) {
	if(num == llGetLinkNumber()){
			// Send the msg in a IM
			//llInstantMessage(last_key, msg);
			llWhisper(0, msg);
	}else if(num == -1){
			//llInstantMessage(last_key, "http request return error!");
			// Avvisa dell'errore
			llWhisper(0,"HTTP request return error!");
			//state default;
		//	llResetScript();
	}

	// Reset!
	llResetScript();

    }

    timer(){
    	//llInstantMessage(last_key, "Server timeout!");
	// Avviso del timeout
	llWhisper(0, "Server timeout!");

        llResetScript();
    }


}



